package gui.edit.listeners;

import gui.edit.components.ActorsPanel;


import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class ListenerActorsListSelection implements ListSelectionListener {

	private ActorsPanel actorsPanel;

	public ListenerActorsListSelection(ActorsPanel actorsPanel){
		setActorsPanel(actorsPanel);
	}

	@Override
	public void valueChanged(ListSelectionEvent listSelectionEvent) {
		boolean adjust = listSelectionEvent.getValueIsAdjusting();
		if (!adjust) {
			JList list = (JList) listSelectionEvent.getSource();
			Object[] selections = list.getSelectedValues();
			
			actorsPanel.getActorsMap().getParamsControl().changeAllActorPresence(false);
			
			actorsPanel.getActorsMap().setSelectedActors(selections);
			for(Object o:selections){
				String name = (String)o;
				actorsPanel.getDataControl().getParamsControl().modifyActorPresence(name, true);
			}
			
			actorsPanel.updateIsolationPanel();
			actorsPanel.updateRelationsPanel();
		}
	}

	public void setActorsPanel(ActorsPanel actorsPanel) {
		this.actorsPanel = actorsPanel;
	}

	public ActorsPanel getActorsPanel() {
		return actorsPanel;
	}

}
